define(function (){
    //生成车速转速图表
    function spdAndEMSpdReptChart(obj,data1, data2, yymmdd,carNo){
        obj.highcharts({
            chart: {
                zoomType: 'x',
                spacingRight: 20
            },
            title: {
                text: carNo + ': ' + yymmdd + '车速转速分析'
            },
            subtitle: {
            },
            credits: {
                enabled: false
            },
            xAxis: {
                type: 'datetime',
                maxZoom: 20*1000,
                title: {
                    text: null
                }
            },
            yAxis: [{
                labels: {
                    formatter: function() {
                        return this.value;
                    },
                    style: {
                        color: '#89A54E'
                    }
                },
                title: {
                    text: '转速(转)',
                    style: {
                        color: '#89A54E'
                    }
                },
                min:0, // 定义最小值
                opposite: true
            }, {
                gridLineWidth: 0,
                title: {
                    text: '车速(转)',
                    style: {
                        color: '#4572A7'
                    }
                },
                min:0, // 定义最小值
                labels: {
                    formatter: function() {
                        return this.value;
                    },
                    style: {
                        color: '#4572A7'
                    }
                }
            }],
            tooltip: {
                dateTimeLabelFormats: {
                    second: '%H时:%M分:%S秒'
                }
            },
            exporting:{
                buttons:{    //配置按钮选项
                    exportButton:{    //配置导出按钮
                        width:50,
                        symbolSize:20,
                        borderWidth:2,
                        borderRadius:0,
                        hoverBorderColor:'red',
                        height:30,
                        symbolX:25,
                        symbolY:15,
                        x:-150,
                        y:20
                    }
                },
                url:"/eltMhy/getSpdAndEMSpdRept.htm",
                filename:'电机车速转速分析',//导出的文件名
                type:'image/png',//导出的文件类型
                width:800    //导出的文件宽度
            },
            series: [{
                name: '车速',
                color: '#4572A7',
                type: 'spline',
                yAxis: 1,
                data: data1
            }, {
                name: '转速',
                color: '#89A54E',
                type: 'spline',
                data: data2
            }]
        });
    };

    //电机运行分析-车速转速图表
    var spdAndEMSpdRept=function(params,initChart,chartWithoutData,$dataChart){
        initChart();
        $.ajaxExt({
            url:"/eltMhy/spdAndEMSpdRept.htm",
            data:params
        }).done(function(result){
            if(!result){
                chartWithoutData();
                return;
            }
            var spdData = [],eMSpdData = [],yymmdd = params.beginTime.substr(0,10);
            $.each(result,function(i){
                var time = result[i].rcrdTime,date;
                date="Date.UTC("+ yymmdd.replace(/-/g,",") + "," + time.substr(11, 2) + "," + time.substr(14, 2) + ","+time.substr(17, 2) + ")";
                spdData.push(eval("[" + date + "," + result[i].spdOfMotVhi + "]"));
                eMSpdData.push(eval("[" + date + "," + result[i].eltMhyActualRtteSpd + "]"));
            });
            spdAndEMSpdReptChart($dataChart,spdData, eMSpdData, yymmdd,params.carNo);
        });
    };

    //生成车速转矩图表
    function spdAndTorqueReptChart(obj,data1, data2, yymmdd,carNo){
        obj.highcharts({
            chart: {
                zoomType: 'x',
                spacingRight: 20
            },
            title: {
                text: carNo + ': ' + yymmdd + '车速转矩分析'
            },
            subtitle: {
            },
            credits: {
                enabled: false
            },
            xAxis: {
                type: 'datetime',
                maxZoom: 20*1000,
                title: {
                    text: null
                }
            },
            yAxis: [{
                labels: {
                    formatter: function() {
                        return this.value;
                    },
                    style: {
                        color: '#89A54E'
                    }
                },
                title: {
                    text: '转速(转)',
                    style: {
                        color: '#89A54E'
                    }
                },
                min:0, // 定义最小值
                opposite: true
            }, {
                gridLineWidth: 0,
                title: {
                    text: '车速(转)',
                    style: {
                        color: '#4572A7'
                    }
                },
                min:0, // 定义最小值
                labels: {
                    formatter: function() {
                        return this.value;
                    },
                    style: {
                        color: '#4572A7'
                    }
                }
            }],
            tooltip: {
                dateTimeLabelFormats: {
                    second: '%H时:%M分:%S秒'
                }
            },
            exporting:{
                buttons:{    //配置按钮选项
                    exportButton:{    //配置导出按钮
                        width:50,
                        symbolSize:20,
                        borderWidth:2,
                        borderRadius:0,
                        hoverBorderColor:'red',
                        height:30,
                        symbolX:25,
                        symbolY:15,
                        x:-150,
                        y:20
                    }
                },
                url:"/eltMhy/getSpdAndEMSpdRept.htm",
                filename:'电机车速转矩分析',//导出的文件名
                type:'image/png',//导出的文件类型
                width:800    //导出的文件宽度
            },
            series: [{
                name: '车速',
                color: '#4572A7',
                type: 'spline',
                yAxis: 1,
                data: data1
            }, {
                name: '转矩',
                color: '#89A54E',
                type: 'spline',
                data: data2
            }]
        });
    };

    // DOIT: 2016-12-23 电机-车速转矩图表
    
    //车速转矩分析
    var spdAndTorqueRept=function(params,initChart,chartWithoutData,$dataChart){
        initChart();
        $.ajaxExt({
            url:"/eltMhy/spdAndTorqueRept.htm",
            data:params
        }).done(function(result){
            if(!result){
                chartWithoutData();
                return;
            }
            var spdData = [],eMSpdData = [],yymmdd = params.beginTime.substr(0,10);
            $.each(result,function(i){
                var time = result[i].rcrdTime,date;
                date="Date.UTC("+ yymmdd.replace(/-/g,",") + "," + time.substr(11, 2) + "," + time.substr(14, 2) + ","+time.substr(17, 2) + ")";
                spdData.push(eval("[" + date + "," + result[i].spdOfMotVhi + "]"));
                eMSpdData.push(eval("[" + date + "," + result[i].eltMhyActualTorque + "]"));
            });
            spdAndTorqueReptChart($dataChart,spdData, eMSpdData, yymmdd,params.carNo);
        });

    };

    //生成电压电流图表
    function vtgAndCrtReptChart(obj,data1, data2, yymmdd,carNo){
        obj.highcharts({
            chart: {
                zoomType: 'x',
                spacingRight: 20
            },
            title: {
                text: carNo + ': ' + yymmdd + '电压电流分析'
            },
            subtitle: {
            },
            credits: {
                enabled: false
            },
            xAxis: {
                type: 'datetime',
                maxZoom: 20*1000,
                title: {
                    text: null
                }
            },
            yAxis: [{ // Primary yAxis
                labels: {
                    formatter: function() {
                        return this.value;
                    },
                    style: {
                        color: '#89A54E'
                    }
                },
                title: {
                    text: '电压',
                    style: {
                        color: '#89A54E'
                    }
                },
                min:0, // 定义最小值
                opposite: true
            }, {
                gridLineWidth: 0,
                title: {
                    text: '电流',
                    style: {
                        color: '#4572A7'
                    }
                },
                min:0, // 定义最小值
                labels: {
                    formatter: function() {
                        return this.value;
                    },
                    style: {
                        color: '#4572A7'
                    }
                }

            }],
            tooltip: {
                dateTimeLabelFormats: { // don't display the dummy year
                    second: '%H时:%M分:%S秒'
                }
            },
            exporting:{
                buttons:{    //配置按钮选项
                    exportButton:{    //配置导出按钮
                        width:50,
                        symbolSize:20,
                        borderWidth:2,
                        borderRadius:0,
                        hoverBorderColor:'red',
                        height:30,
                        symbolX:25,
                        symbolY:15,
                        x:-150,
                        y:20
                    }
                },
                url:"/eltMhy/getVtgAndCrtRept.htm",
                filename:'电机电压电流分析',//导出的文件名
                type:'image/png',//导出的文件类型
                width:800    //导出的文件宽度
            },
            series: [{
                name: '电压(V)',
                color: '#4572A7',
                type: 'spline',
                data: data1
            }, {
                name: '电流(mA)',
                color: '#89A54E',
                type: 'spline',
                yAxis: 1,
                data: data2
            }]
        });
    };

    // DOIT: 2016-12-23 电机-电压电流图表
    
    //电机运行分析-电压电流图表
    var vtgAndCrtRept=function(params,initChart,chartWithoutData,$dataChart){
        initChart();
        $.ajaxExt({
            url:"/eltMhy/vtgAndCrtRept.htm",
            data:params
        }).done(function(result){
            if(!result){
                chartWithoutData();
                return;
            }
            var vData = [],aData = [], yymmdd = params.beginTime.substr(0,10);
            $.each(result,function(i){
                var time = result[i].rcrdTime,date;
                date="Date.UTC("+ yymmdd.replace(/-/g,",") + "," + time.substr(11, 2) + "," + time.substr(14, 2) + ","+time.substr(17, 2) + ")";
                vData.push(eval("[" + date + "," + result[i].eltMhyCtrlBusbarVtg + "]"));
                aData.push(eval("[" + date + "," + result[i].eltMhyCtrlBusbarEltCrt + "]"));
            });
            vtgAndCrtReptChart($dataChart, vData, aData, yymmdd,params.carNo);
        });
    };
    return {
        spdAndEMSpdRept: spdAndEMSpdRept,
        spdAndTorqueRept:spdAndTorqueRept,
        vtgAndCrtRept:vtgAndCrtRept
    };
});